package com.bloomingstars.bluepad.comm;
/*
 * BlueEnumeration.java
 *
 * Created on 1 aprile 2007, 22.35
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

import java.util.Enumeration;
import java.util.Hashtable;

/**
 *
 * @author vega
 */
public abstract class BlueEnumeration
{
     protected BlueEnumeration()
     {
         
     }
    
     public static int INVALID_CODE = -999999999;
    
     public static int getCodeFromString(String s)
     {
         Enumeration keys = table.keys();
         boolean foundFlag = false;
         Integer key = null;
              
         for (; keys.hasMoreElements() && !foundFlag; )
         {
             key = (Integer) keys.nextElement();
           
             Object o = table.get(key);
           
             if (o != null && o instanceof Integer)
             {
                 foundFlag = true;
             }
         }
       
         if (foundFlag)
             return key.intValue();
         else
             return INVALID_CODE;
     }
   
     public static String getStringFromCode(int code)
     {
         Object o = table.get(new Integer(code));
         String result = "INVALID_CODE";
       
         if (o != null && o instanceof String)
         {
             result = (String) o;
         }
       
         return result;
     }
       
   
     protected abstract void loadTable();
   
     protected static Hashtable table = new Hashtable();   
}
